
/*
	app_window表示一个view显示，占据整个display。不同的view内容不同，
	在实际app中可以有多个view表示不同的方面内容，对应就有多个不同app_window
*/

#include "tp_typedef.h"
#include "tp_display.h
#include "tp_bitmap.h"
#include "tp_memory.h"
#include "tp_event.h"
#include "tp_app_window.h"
#include "tp_wnd_manager.h"

typedef struct _PrivInfo
{
	TpColor bg_color;
	TpBitmap* canvas; /* 每个window应该都有一个canvas，保存当前窗口的绘制结果 */
}PrivInfo;

static TpRet tp_app_window_on_event(TpWidget* thiz, TpEvent* event)
{
	DECL_PRIV(thiz, priv);

	if(NULL == priv || NULL == event)
	{
		return TP_RET_FAIL;
	}

	/* TODO:
       1,调用Hook
       2,将事件分发到焦点控件
     */

	return TP_RET_OK;
}

static void tp_app_window_destroy(TpWidget* thiz)
{
	DECL_PRIV(thiz, priv);

	if (NULL != priv)
	{
		tp_bitmap_destroy(priv->canvas);
		tp_free(thiz);
	}

	return;
}

TpWidget* tp_app_window_create(TpWindowType type)
{
	TpWidget* thiz = NULL;
	TpDisplay* display = NULL;
	TpWndManager* wnd_manager = NULL;

	thiz = (TpWidget*)tp_alloc(sizeof(TpWidget) + sizeof(PrivInfo));
	if (NULL != thiz)
	{
		DECL_PRIV(thiz, priv);

		tp_default_app_wnd_bg(&priv->bg_color);
		display = tp_default_display();
		wnd_manager = tp_default_wnd_manager();

		priv->canvas = tp_bitmap_create(tp_display_width(display), tp_display_height(display), &priv->bg_color);
		if (NULL == priv->canvas)
		{
			tp_free(thiz);
			thiz = NULL;
		}
		else
		{
			thiz->on_event = tp_app_window_on_event;
			thiz->destroy = tp_app_window_destroy;

			wnd_manager->add(wnd_manager, thiz);
		}
	}

	return thiz;
}